package com.lic.lesson2db.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author : LiChengLin
 * @Description:
 * @Date:Created in 2018/9/17 21:54
 * @Modified By:
 **/
@Controller
@RequestMapping("user")
public class HelloController {
    private static Logger log=LoggerFactory.getLogger(HelloController.class);
    @RequestMapping("index")
    public ModelAndView index(){
        log.info("###########");
        ModelAndView view = new ModelAndView("index");
        view.addObject("name","lic");
        return view;
    }
    @RequestMapping("login")
    @ResponseBody
    public String login(String name, String password, HttpServletRequest req){
        if(!StringUtils.isEmpty(name)&&name.equals("lic")&&password.equals("123")){
            req.getSession().setAttribute("user","lic");
            return "true";
        }
        return "false";
    }
}
